/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Graph;

/**
 *
 * @author Andrew
 */
public class Edge<T> {
    private Node<T> n1;
    private Node<T> n2;

    public Edge(Node<T> n1, Node<T> n2) {
        if (n1 == null || n2 == null)
            throw new NullPointerException();
        this.n1 = n1;
        this.n2 = n2;
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Edge))
            return false;
        Edge edge = (Edge)o;

        //new Edge(new Node(1), new Node(2)).equals(new Edge(2), new Edge(1))
        //are true
        return ((edge.n1.equals(n1) && edge.n2.equals(n2)) || (edge.n1.equals(n2) && (edge.n2.equals(n1))));
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 73 * hash + (this.n1 != null ? this.n1.hashCode() : 0);
        hash = 73 * hash + (this.n2 != null ? this.n2.hashCode() : 0);
        return hash;
    }
}